var class_num=location.search;
class_num=class_num.split('?')[1];
$('header .title').append(class_num);
$('.card-courseware a').attr('href','file_courseware.html?'+class_num);
if (islogin()) {

    select_homework();
    select_submmit();
    $('#select_homework').change(function () {
        $('.file_box2').empty();
        select_submmit();
    });

}
else window.location.href='../../index.html';
function select_homework() {
    $.post({
        url:'../../requests/teacher/select_homework.php',
        data:{'class':class_num},
        async:false,
        success:function (data) {
            for (var i = 0; i < data.length; i++) {

                //将作业标题插入select标签
                var dom_select="<option value='"+data[i].Id+"'>"+data[i].title+"</option>";
                $('#select_homework').append(dom_select);

                if (data[i].attach!=null){
                    var att_name=data[i].attach.split('requests/Files/20110212/homework/attach/')[1];
                    var dom1="  <li class='item-content'>\n" +
                        "                        <div class=\"item-inner\">\n" +
                        "                            <div class='item-title'>\n" +
                        "                                <span>附件：</span>\n" +
                        "                                <span>"+att_name+"</span>\n" +
                        "                            </div>\n" +
                        "                            <div class='item-after'><a download href='../../"+data[i].attach+"'>下载<span class='icon icon-download'></span></a></div>\n" +
                        "                        </div>\n" +
                        "                    </li>";
                }
                else dom1="";
                if (data[i].answer != null) {
                    var answer_name=data[i].answer.split('requests/Files/20110212/homework/answer/')[1];
                    var dom2="<li class='item-content'>\n" +
                        "                        <div class=\"item-inner\">\n" +
                        "                            <div class='item-title'>\n" +
                        "                                <span>答案：</span>\n" +
                        "                                <span>"+answer_name+"</span>\n" +
                        "                            </div>\n" +
                        "                            <div class='item-after'><a download href='../../"+data[i].answer+"'>下载<span class='icon icon-download'></span></a></div>\n" +
                        "                        </div>\n" +
                        "                    </li>";
                }
                else dom2="";

                var dom="<div class='list-block'>" +
                            "<ul>" +
                                "<li class='item-content'>" +
                                    "<div class='item-inner'><div class='item-title'>标题</div><div class='item-after'>"+data[i].title+"</div></div>"+
                                "</li>"+
                                dom1+dom2+
                            "</ul>"+
                        "</div>";
                $('.file_box1').append(dom);
            }
        }
    });
}


function select_submmit() {
    if ($('#select_homework').val()==""){
        $('#tab2').append('没有作业');
    }
    else {
        $.post({
            url:'../../requests/teacher/select_all_submit.php',
            data:{'class':class_num,'homework':$('#select_homework').val()},
            async:false,
            success:function (data) {
                console.log(data);
                for (var i = 0; i < data.length; i++) {
                    var att_name=data[i].attach.split('requests/Files/20110212/homework/submit/')[1];
                    var dom=" <div class='list-block'><ul>\n" +
                        "                                   <li class=\"item-content\">\n" +
                        "                                       <div class=\"item-inner\">\n" +
                        "                                           <div class=\"item-title\">姓名</div>\n" +
                        "                                           <div class=\"item-after\">"+data[i].stuname+"</div>\n" +
                        "                                       </div>\n" +
                        "                                   </li>\n" +
                        "                                   <li class=\"item-content\">\n" +
                        "                                       <div class=\"item-inner\">\n" +
                        "                                           <div class=\"item-title\">学号</div>\n" +
                        "                                           <div class=\"item-after\">"+data[i].student+"</div>\n" +
                        "                                       </div>\n" +
                        "                                   </li>\n" +
                        "                                   <li class=\"item-content\">\n" +
                        "                                       <div class=\"item-inner\">\n" +
                        "                                           <div class=\"item-title\">文件名</div>\n" +
                        "                                           <div class=\"item-after\">"+att_name+"</div>\n" +
                        "                                       </div>\n" +
                        "                                   </li>\n" +
                        "                                   <li class=\"item-content\">\n" +
                        "                                       <div class=\"item-inner\">\n" +
                        "                                           <div class=\"item-title\"></div>\n" +
                        "                                           <div class=\"item-after\"><a href='../../"+data[i].attach+"'>下载<span class=\"icon icon-download\"></span></a></div>\n" +
                        "                                       </div>\n" +
                        "                                   </li>\n" +
                        "                               </ul></div>";
                    $('.file_box2').append(dom);
                }
            }
        });
    }
}